<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <title>采购项目</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
<div class="box box-primary" id="more" style="width:110px;height:20px;background-color:#222c32;position:absolute;z-index:9999;left:850px;top:100px;display:none;font-size:12px;border-top-color:#222c32;">
            <!-- <div class="box-header with-border">
                	更多操作
            </div> --><!-- /.box-header -->
            <div class="box-body home-message" id="moreOp">
            </div>
        </div>
    <section class="content-header">
        <h1>招标项目管理</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active">药品招标管理</li>
            <li class="active">采购项目管理</li>
            <li class="active">招标项目管理</li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class=" form-inline">
                	<div class="form-group form-group-xs">
                	    <label for="txtDrugName">项目名称：</label>
					    <select class="form-control" style="width:220px;" id="projId" name="projId"></select>
                	</div>
                    <div class="form-group form-group-xs form-status">
                        
                    </div>
                    <button type="button" onclick="gridSerch()" class="btn btn-success btn-sm">查&nbsp;询</button>
                </div>
            </div>
        </div>

        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>

        <div class=" box box-warning bottongroup">
        <a href='${ctx}/bidProject/toSaveOrUpdate.html' class="btn btn-default btn-sm">新&nbsp;增</a>
        <button  class="btn btn-default btn-sm"  onclick="batchChangeStatus(1)">启&nbsp;用</button>
        <button  class="btn btn-default btn-sm"  onclick="batchChangeStatus(0)">停&nbsp;用</button>
        </div>
    </section>
    <form action="${ctx}/bidProjCompany/toList.html" method="post" id="Form">
    <input type="hidden" name="projId" id="projId">
    <input type="hidden" name=newname id="newname">
    </form>
     <form action="${ctx}/bidProject/toHospList.html" method="post" id="FormAddhosp">
    <input type="hidden" name="projIdAddhosp" id="projIdAddhosp">
    <input type="hidden" name="name" id="name">
    </form>
      <form action="${ctx}/bidProject/toCompList.html" method="post" id="FormAddcomp">
    <input type="hidden" name="projIdAddcomp" id="projIdAddcomp">
    <input type="hidden" name="compName" id="compName">
    </form>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
        $(function () {
            $("#gridlist").jqGrid({
                url: "${ctx}/bidProject/getDataList.html",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                height: 270,											
                colNames: ['操作','projId','项目名称','采购开始日期','采购结束日期', '状态', '招标目录','投标药品数','中标药品数','生产企业数','配送企业数','医疗机构数'],
                colModel: [
                    { name: 'operate', width: 200,sortable: false, align:"center",
                    	formatter : function(val, opts, rowdata) {
                    		var str = "";
                    		str += "<a href='${ctx}/bidProject/toSaveOrUpdate.html?projId="+rowdata.projId+"'; style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px 0px' class='opIcon' title='编辑'></a>";
                    		str += "<a href='${ctx}/bidProject/toAddHospList.html?projId="+rowdata.projId+"&name="+rowdata.name+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -160px 0px' class='opIcon' title='添加医疗机构'></a>";
                    		str += "<a href='${ctx}/bidProject/toDrugqualityspecList.html?projId="+rowdata.projId+"&name="+rowdata.name+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -120px -20px' class='opIcon' title='按品规添加药品'></a>";
							str += "<a href='${ctx}/bidProject/toImportDrugByCatalog.html?projId="+rowdata.projId+"&name="+rowdata.name+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -100px -20px' class='opIcon' title='按目录添加药品'></a>";
							str += "<a href='${ctx}/bidProject/toSetPassword.html?projId="+rowdata.projId+"&name="+rowdata.name+"' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -20px -60px' class='opIcon' title='密码管理'></a>";
							str += "<a href='javascript:toCheckPassword(\""+rowdata.projId+"\",\""+rowdata.name+"\");' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -140px -20px' class='opIcon' title='时间管理'></a>";
                    		//if (rowdata.status=="1"){
                    		//str += "<a href='${ctx}/bidProject/toSaveOrUpdate.html?projId="+rowdata.projId+"'; style=\"display:block;height:24px;width:40px;margin:0 ;padding:0 ;float:left;line-height:24px;font-size: 13px;\">编辑</a>";
	               			//str+="<div id='"+rowdata.projId+"d' onmouseover=\"over('"+rowdata.projId+"','"+rowdata.projId+"','"+rowdata.name+"');\"  style='height:24px;width:50px;margin:0 ;padding:0 ;float:left;line-height:24px'><a>更多...</a></div>"; 
                    		//} 
                    		return str;
                    	}	
                    },
                    { name: 'projId', key:true,hidden:true,width: 40, align: 'center' ,sortable: false},
                    { name: 'name', width: 150, align: 'left' ,sortable: false},
                    { name: 'starttime', width: 120, align: 'center' ,sortable: false},
                    { name: 'endtime', width: 120, align: 'center' ,sortable: false},
                    { name : 'status', width : 80, align : 'center', sortable : false,
							formatter : function(val, opts,rowdata) {
						    	if (val == 1) {
									return "启用";
							} else if (val == 0) {
									return "停用";
							}
					}},
                    { name: 'drugCount', width: 70, align: 'center' ,sortable: false,formatter: function (val, opts, rowdata) {return "<a href=\"toHaveAddDrugList.html?projId="+rowdata.projId+ "&name="+rowdata.name+"\">"+val+"</a>";}},
                    { name: 'projProddrugCount', width: 70, align: 'center' ,sortable: false,formatter: function (val, opts, rowdata) {return "<a href=\"toProjDrugList.html?projId="+rowdata.projId+ "&name="+rowdata.name+"\">"+val+"</a>";}},
                    { name: 'biddingDrugCount', width: 70, align: 'center' ,sortable: false,formatter: function (val, opts, rowdata) {return "<a href=\"toBindDrugsList.html?projId="+rowdata.projId+ "&name="+rowdata.name+"\">"+val+"</a>";}},
                    { name: 'proCompCount', width: 70, align: 'center' ,sortable: false,formatter: function (val, opts, rowdata) {return "<a href=\"toJoinProCompList.html?projId="+rowdata.projId+"&name="+rowdata.name+"\">"+val+"</a>";}},
                    { name: 'delCompCount', width: 70, align: 'center' ,sortable: false,formatter: function (val, opts, rowdata) {return "<a href=\"toAddedBidProjectCompsList.html?projId="+rowdata.projId+"&name="+rowdata.name+"\">"+val+"</a>";}},
                    { name: 'hospCount', width: 70, align: 'center' ,sortable: false,formatter: function (val, opts, rowdata) {return "<a href=\"toHaveAddHospsList.html?projId="+rowdata.projId+"&name="+rowdata.name+"\">"+val+"</a>";}}
                ],
                rowNum: 0,
                rownumbers: true,
                viewrecords: true,
                multiselect: true, 
                caption: "采购项目列表",
                jsonReader: {
                    repeatitems: false  
                },
                loadComplete: function (data) { //完成服务器请求后，回调函数
                	formatSelect("#projId",data.rows);
                	var projId = data.form;
                	if(!gg()){
                		$('.form-status').html("<label for='txtDrugForm'>项目状态：</label><select class='form-control'  id='status' name='status'><option value=''>请选择</option><option value='1'>启用</option><option value='0'>停用</option></select>");
                	}
               		function gg(){
	                	if(projId!=null && projId!=""){
	                	$("#projId").find("option").each(function(){
	                			if($.trim($(this).val()) == $.trim(projId)){
	                    			$(this).attr("selected",true).parents("#projId").attr("disabled","disabled");
	                    		}
	                	 });
	                	return true;
	                  }else{
	                	  return false;
	                  }
	                }
               		
                }
            });
            
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false }).closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });;
            $(window).trigger("resize");
        });
        //查询
        function gridSerch() {
        	var projId =$("#projId").val();
        	var status = $("#status").val();
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{
    	        		"projId":projId,
    	        		"status":status
    	        		}
    	    }).trigger("reloadGrid"); //重新载入  
    	}
        //添加医疗机构
        function toAddhosp(projId,name){
        	$("#projIdAddhosp").val(projId);
        	$("#proName").val(name);
        	$("#FormAddhosp").submit();
        }
        //配送企业链接
        function getForm(projId,name){
        	$("#projId").val(projId);
        	$("#newname").val(name);
        	$("#Form").submit();
        }
        
        
       //启用、停用
        function switchStatus(id, status) {
        	var msg = "";
        	if (status == 1){
        		msg = "启用";
        	} else if (status == 0){
        		msg = "停用";
        	}
        	 $.HN.message.confirm('确定'+msg+'吗？', '', '').on(function (e) {
        		 if(e){
        			 $.post("${ctx}/bidProject/switchStatus.html", {
        				 projId : id,
        				 status : status
        	    		}, function(result) {
        	    			
        	    			if (result == "success") {
        	    				gridSerch();
        	    				$.HN.message.alert("操作成功！", "消息", "success");
        	    			} else {
        	    				$.HN.message.alert("操作失败！", "消息", "error");
        	    			}
        	    		}, "json")
        		 }
        	 });
    	} 
        
       //停用
       function batchChangeStatus(status) {
    		var msg = "停用";
    		if(status == 1){
    			var msg = "启用";
    		}
    		var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
    		if (rowIds.length <= 0) {
    			$.HN.message.alert("请选择要操作的行！", "消息", "warn");
    			return;
    		}
    		$.HN.message.confirm("确定"+msg+"吗？", '', '').on(function (e) {
                if (e) {
    		
    		var list = [];
    		for (var i=0; i<rowIds.length; i++) {
    			rowId = rowIds[i];
    			var rowData = $("#gridlist").jqGrid('getRowData',rowId);
    			list.push({"projId":rowData.projId,"status":status});
    		}
    		$.post("switchStatus.html", {
    			"array" : json.jsonToString(list),"projId":rowData.projId,"status":status
    		}, function(result) {
    			if (result="success") {
    				$.HN.message.alert("操作成功！", "消息", "success");
    				document.location.href="${ctx}/bidProject/toList.html";
    			} else {
    				$.HN.message.alert("操作失败！", "消息", "error");
    			}
    		}, "json");
                }
    		}); 
    	}
       
        //设置招标阶段设置
        function toCheckPassword(projId){
        	$.post("${ctx}/bidProject/getPasswordInfo.html", {
        		projId:projId
        	}, function(result){
        		if(result.firstSetPswd){
        			$.HN.message.alert("请设置密码！", "消息","success");
        		}else{
        			window.location.href="${ctx}/bidProject/toCheckPassword.html?projId="+projId;
        		}
        	});
        	
        }
      //鼠标移动事件
        function over(id,projId,name){//鼠标移入
        	$("#moreOp").children().remove();
        	var coord=$("#"+id+"d").offset();
        	$("#more").css("top",coord.top-1);
        	$("#more").css("left",coord.left-$("#more").width());
        	$("#more").show();  
        	$("#more").css("height",100);
            $("#more").css("padding-top",6);
        	$("#moreOp").append("<a id='"+id+"w'  href='${ctx}/bidProject/toAddHospList.html?projId="+projId+"&name="+name+"' style='color:#fff;float:left;display:block'>添加医疗机构</a></br>");
        	$("#moreOp").append("<a id='"+id+"w'  href='${ctx}/bidProject/toDrugqualityspecList.html?projId="+projId+"&name="+name+"' style='color:#fff;float:left;display:block'>按品规添加药品</a>");
        	$("#moreOp").append("<a id='"+id+"w'  href='${ctx}/bidProject/toImportDrugByCatalog.html?projId="+projId+"&name="+name+"' style='color:#fff;float:left;display:block'>按目录添加药品</a>");
        	$("#moreOp").append("<a id='"+id+"w'  href='${ctx}/bidProject/toSetPassword.html?projId="+projId+"&name="+name+"' style='color:#fff;float:left;display:block'>密码管理</a>");
        	$("#moreOp").append("<a href='javascript:toCheckPassword(\""+projId+"\",\""+name+"\");' style='color:#fff;float:left;display:block'>时间管理</a>");
        }
        //鼠标移出，隐藏
    	var flag = false;
	    var mouseX=0;
	    var mouseY=0;
        $(document).mousemove(function(e){
			  mouseX=e.pageX;
			  mouseY=e.pageY;
			  var coord=$("#more").offset();
	   		  if((mouseX<coord.left||mouseX>(coord.left+$("#more").width())||mouseY<coord.top||
	   				  mouseY>(coord.top+$("#more").height()))&&(mouseX<(coord.left+$("#more").width())||
	   						  mouseX>(coord.left+$("#more").width()+50)||mouseY<(coord.top+1)||mouseY>(coord.top+24+1))){
	   		  	  $("#more").hide();
	   		  } 
		});
        
        //密码修改
        function toCheckAndWritePassword(projId,name){
        	$.post("/medstgmini/bidProject/getPasswordInfo.html", {
        		projId:projId
        	}, function(result){
        		var result = eval("("+result+")");
        		if(result.firstSetPswd){
        			$.HN.message.alert("请先设置密码！", "消息","error");
        			document.location="/medstgmini/bidProject/toSetPassword.html?projId="+projId+"&name="+name;
        		}else{
        			 $.HN.dialog.open({
        	             id:"password",
        	             title:"输入密码",
        	             url:" /medstgmini/bidProject/toWritePassword.html?projId="+projId+"&name="+name,
        	             width:"800px",
        	             height:"300px"
        	             }
        	         ); 
        		}
        	});
        	
        }
        //设置招标阶段设置
        function toCheckPassword(projId,name){
        	$.post("/medstgmini/bidProject/getPasswordInfo.html", {
        		projId:projId
        	}, function(result){
        		if(result){
	        		var result = eval("("+result+")");
	        		if(result.firstSetPswd){
	        			$.HN.message.alert("请设置密码！", "消息","warn");
	        		}else{
	        			 $.HN.dialog.open({
	        	             id:"password",
	        	             title:"输入密码",
	        	             url:" /medstgmini/bidProject/toCheckPassword.html?projId="+projId+"&name="+name,
	        	             width:"800px",
	        	             height:"300px"
	        	             }
	        	         ); 
	        		}
        		}else{
        			$.HN.message.alert("数据异常！", "消息","error");
        		}
        	});
        }
    </script>
</body>
</html>